<?php

/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2022-04-24
 * Time: 10:31:43
 * Info:
 */

namespace app\index\controller;

use support\Request;
use Gregwar\Captcha\CaptchaBuilder;

class IndexController
{

    public function index(Request $request)
    {
        $version = "v1.4.7";

        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p>WebmanFramework -'.$version.'<br/><span style="font-size:30px;">webman是一款基于workerman开发的高性能HTTP服务框架。</span></p><span style="font-size:25px;">Huicmf_webman</span></div></think>';
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

    /**
     * 输出验证码图像
     */
    public function captcha(Request $request)
    {
        // 初始化验证码类
        $builder = new CaptchaBuilder;
        // 生成验证码
        $builder->build();
        // 将验证码的值存储到session中
        $request->session()->set('captcha', strtolower($builder->getPhrase()));
        // 获得验证码图片二进制数据
        $img_content = $builder->get();

        // 输出验证码二进制数据
        return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
    }
}
